<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="调用时间" style="width: 308px">
        <el-date-picker
          v-model="dateRange"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[
            new Date(2000, 1, 1, 0, 0, 0),
            new Date(2000, 1, 1, 23, 59, 59),
          ]"
        ></el-date-picker>
      </el-form-item> -->
      <el-form-item label="帖子标题" prop="title">
        <el-input
          @change="handleQuery"
          v-model="queryParams.title"
          placeholder="选填写帖子标题"
          clearable
          style="width: 240px"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="开始时间" prop="startDate">
        <el-date-picker
          clearable
          v-model="queryParams.startDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker
          clearable
          v-model="queryParams.endDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择结束时间"
        >
        </el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
<!--        <el-col :span="1.5">-->
          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['system:aiRechargeRecords:export']"
          >导出</el-button
          >
<!--        </el-col>-->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <right-toolbar
        v-model:showSearch="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="matterList">
      <el-table-column label="帖子类型" prop="type">
        <template #default="scope">
          <div v-for="item in post_type">
            {{ item.value == scope.row.type ? item.label : "" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="帖子标题" prop="title" />
      <el-table-column label="状态" prop="status">
        <template #default="scope">
          {{ scope.row.status == "0" ? "正常" : "屏蔽" }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间" prop="createTime">
        <template #default="scope">
          <div style="display: flex; flex-direction: column">
            <div>
              {{ parseTime(scope.row.createTime, "{y}-{m}-{d} ") }}
            </div>
            <div>
              {{ parseTime(scope.row.createTime, " {h}:{i}:{s}") }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="分享数" align="center" prop="shareNum" />
      <el-table-column label="阅读数" align="center" prop="readCount" />
      <el-table-column label="评论数" align="center" prop="countNum" />
      <el-table-column label="点赞数" align="center" prop="likes" />

      <el-table-column label="点击率" prop="clickRate">
        <template #default="scope"> {{ scope.row.clickRate * 100 }}% </template>
      </el-table-column>
      <el-table-column label="停留时间" prop="svgStayTime">
        <template #default="scope">
          <span>{{ parseConvertTime(scope.row.svgStayTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="跳转率" align="title">
        <template #default="scope"> {{ scope.row.skipRate * 100 }}% </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="AiRechargeRecords">
import { matterListApi } from "@/api/system/aiRechargeRecords";
import { parseConvertTime } from "@/utils/ruoyi";

const { proxy } = getCurrentInstance();
const { post_type } = proxy.useDict("post_type");
console.log("post_type", post_type);
const matterList = ref([]);
const matterList2 = ref([]);
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const dateRange = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    rechargeAmount: undefined,
    points: undefined,
    sortType: 0,
    title: undefined,
  },
});

const { queryParams, form } = toRefs(data);

/** 查询极客小程序ai换发充值记录列表 */
function getList() {
  console.log(queryParams.value);
  loading.value = true;
  // if (dateRange.value != null && dateRange.value.length > 1) {
  //   queryParams.value.beginTime = dateRange.value[0];
  //   queryParams.value.endTime = dateRange.value[1];
  // }
  matterListApi(queryParams.value).then((response) => {
    console.log(response.rows);

    matterList.value = response.rows;
    loading.value = false;
    total.value = response.total;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    rechargeAmount: null,
    points: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    delFlag: null,
  };
  dateRange.value = null;
  proxy.resetForm("aiRechargeRecordsRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "/business/matterManage/export",
    {
      ...queryParams.value,
    },
    `aiRechargeRecords_${new Date().getTime()}.xlsx`
  );
}

getList();
</script>
